package com.ht.api.request.call;

import com.ht.api.db.Db;
import com.ht.api.db.annotate.FuncEdit;
import com.ht.api.db.annotate.FuncGroup;
import com.ht.api.db.annotate.FuncId;
import com.ht.api.db.annotate.FuncName;
import com.ht.api.db.annotate.FuncParam;
import com.ht.api.db.annotate.FuncParams;
import com.ht.api.db.bean.DataResult;
import com.ht.api.db.bean.SessionBean;
import com.ht.api.db.exception.HtException;
import com.ht.api.db.request.IHandleRequest;
import com.ht.api.db.util.HtUtil;

import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@FuncId("1914923332071985152")
@FuncGroup("")
@FuncParams({
	@FuncParam(name = "接口名称", code = "name", value = "这是一个测试接口"),
	@FuncParam(name = "接口key", code = "key", value = "TestMqCall"),
})

@FuncEdit("call")
@FuncName("修改call接口")
public class CallEdit implements IHandleRequest {

	@Override
	public void before(SessionBean me, JSONObject param, DataResult result) {
		String mainId = param.getStr("main_id");
		String key = param.getStr("key");
		boolean isExists = Db.createSqlParser("call").where("key", key).where("mainId", "!=", mainId).hasRow();
		if (isExists) {
			throw new HtException("call接口key已存在，key:{}" + key);
		}
	}

	public static void main(String[] args) {
		System.err.println("@FuncId>>" + HtUtil.getId());

//		JSONObject result = CallTestUtil.autoTest(new Object(){}.getClass().getEnclosingClass().getSimpleName());
//		System.err.println(result.toStringPretty());
	}
}
